<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    import="com.yaodian100.core.common.utils.JspUtil,com.yaodian100.crm.workorder.entity.WorkOrder,com.yaodian100.crm.workorder.entity.TaskGroup,java.text.*, com.yaodian100.crm.cs.entity.*"
    %>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="/WEB-INF/tld/pageable.tld" prefix="pageable"%>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<%!
void loopWoChild(StringBuffer result, String orgQuestionId, Integer lag){
	try{
	Object[] qs=JspUtil.queryByHql("from Question where orgQuestionId=?", new Object[]{orgQuestionId},null);
	if(qs==null || qs.length==0){
		
	}else{
	Question q=(Question)qs[0];
	System.out.println("qid:"+q.getId());
	String hql="from WorkOrder where domainId =? order by createDate desc";
	SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
	Object[] wos=JspUtil.queryByHql(hql, new Object[]{q.getId()},null);
	if(wos!=null){
		for(int i=0;i<wos.length;i++){
			WorkOrder wo=(WorkOrder)wos[i];
		
			 result.append("<tr class=\""+(i % 2 == 0 ? "bg-yl" : "")+"\">");
			 result.append("<td>"+lag+"</td>");
			result.append("<td><a href='/ecadmin/cs/page.do?iamlazy=viewQuestion&id="+wo.getId()+"'>明细</a></td>");
			result.append("<td>"+wo.getId()+"</td>");
			result.append("<td>"+wo.getQuestion().getId()+"</td>");
			result.append("<td>");
			if(wo.getQuestion().getExtraValue().get("orderId")!=null){
				result.append(wo.getQuestion().getExtraValue().get("orderId").getValue());
			}
			
			result.append("</td>");
			result.append("<td>");
				result.append(wo.getQuestion().getDescription());
				result.append("</td>");
				result.append("<td>");
				result.append(wo.getComment());
				result.append("</td>");
			result.append("<td>");
			String priority="函件";
			if(wo.getPriority()!=null){
			if(wo.getPriority()==0){
				priority="函件";
			}
			if(wo.getPriority()==1){
				priority="普通件";
			}
			if(wo.getPriority()==2){
				priority="急件";
			}
			if(wo.getPriority()==3){
				priority="特急件";
			}
			}
			result.append(priority);
				result.append("</td>");
				String status=JspUtil.menuOption("WorkOrder.status", JspUtil.toString(wo.getStatus())).getName();
				result.append("<td>"+status+"</td>");
				result.append("<td>");
				String typeName="";
				if(wo.getQuestion().getType().getName().equals("CommonQuestion")){
					if(wo.getQuestion().getExtraValue().get("isProductQAA")!=null){
						if("true".equals(wo.getQuestion().getExtraValue().get("isProductQAA").getValue())){
							typeName="商品问答";
						}else{
							typeName="客服问答";
						}
					}else{
						typeName="客服问答";
					}
				}else{
					typeName=wo.getQuestion().getType().getDescription();
				}
				result.append(typeName);

				
				result.append("</td>");
				result.append("<td>");
				if(wo.getOwner()!=null)
				result.append(wo.getOwner().getUsername());
				result.append("</td>");
				result.append("<td>");
				String groupName="";
				if(wo.getResponseGroup()!=null){
					groupName=((TaskGroup)JspUtil.get(TaskGroup.class.getName(), wo.getResponseGroup())).getName();
					result.append(groupName+"("+wo.getResponseGroup()+")");	
				}

				result.append("</td>");
				result.append("<td>");
				if(wo.getApproveGroup()!=null){
					groupName=((TaskGroup)JspUtil.get(TaskGroup.class.getName(), wo.getApproveGroup())).getName();
					result.append(groupName+"("+wo.getApproveGroup()+")");
				}
				result.append("</td>");
				result.append("<td>");
				String approveStatus="";
				if(wo.getApproveStatus()==0){
					approveStatus="待审核";
				}else if(wo.getApproveStatus()==1){
					approveStatus="已核可";
				}else if(wo.getApproveStatus()==2){
					approveStatus="<span style=\"color:red\">已注销</span>";
					
				}
				result.append(approveStatus);
				
				result.append("</td>");
				result.append("<td>");
				result.append(sdf.format(wo.getCreateDate()));
				result.append("</td>");
				result.append("<td>");
				
				Object[] replyWorkOrders=JspUtil.queryByHql("from WorkOrder where parent.id=?", new Object[]{wo.getId()}, null);
				if(replyWorkOrders!=null && replyWorkOrders.length>0){
					WorkOrder woParent=(WorkOrder)replyWorkOrders[0];
					if(woParent.getFinishTime()!=null){
						result.append(sdf.format(woParent.getFinishTime()));
					}else{
						result.append("尚未回覆");
					}
				}else{
					result.append("未转单");
				}
				
				result.append("</td>");
			result.append("</tr>");
			if(wo.getParent()==null)
			loopWoChild(result, wo.getQuestion().getId(), ++lag);
			
		}
	}
	}
	}catch(Exception e){
		e.printStackTrace();
	}
}
%>
<script>
$().ready( function() {
	$("#workOrderId").numeric();
});
$(function(){
		if(document.theForm.taskGroupId){
		if(document.theForm.taskGroupId.value!=''){
			doAR('/ecadmin/cs/taskGroup/page.do?iamlazy=taskGroupUsers&taskGroupId='+document.theForm.taskGroupId.value+'&columnName=createUser&username=${param.createUser}', 'createUser');
		}
		}
		if(document.theForm.myTaskGroupId){
		if(document.theForm.myTaskGroupId.value!=''){
			doAR('/ecadmin/cs/taskGroup/page.do?iamlazy=taskGroupUsers&taskGroupId='+document.theForm.myTaskGroupId.value+'&columnName=responser&username=${param.responser}', 'responser');
		}
		}      
});
</script>
${pu:reqSet('user', pu:user()) }
${pu:listAdd('guparams', user.username) }
${pu:reqSet('groupUsers', pu:queryByHql('from TaskGroupUser where user.username=?', pu:arrayGet('guparams'), null)) }

<c-rt:if test="${!empty param.domainId }">
${pu:reqSet('domainId', param.domainId) }

</c-rt:if>
<style>
<!--
.tb-2{border:1px solid #ccc; width:100%; vertical-align:text-bottom;}
.tb-2 th{background:#ffe9b5; color:#631;text-align:center; font-weight:bold; font-size:13px; padding:.25em;*padding:.35em .2em .15em;vertical-align:middle}
.tb-2 td{padding:6px 5px;*padding:6px 5px 4px;text-align:center;}

.tb-2 td {
text-align:left;
}
.tb-2 tr:hover{background:#fffae5;}
.ntb tbody{border:1px solid #000;

}
.ntb th{
background:#ffe9b5; color:#631;text-align:center; font-weight:bold; font-size:13px; padding:.25em;*padding:.35em .2em .15em;vertical-align:middle
}
.ntb td{
padding:6px 5px;
}
-->
</style>
<c-rt:if test="${empty param.fromOrder}">
<c-rt:set var="tp" value="${pu:pageableTag('tpp', 10, 10)}"/>
${pu:listAdd('groupAllPara', user.username) }
${pu:reqSet('groupUsersAllGroups', pu:customHqlQuery('from TaskGroupUser where user.username=?', pu:arrayGet('groupAllPara'), null, 0)) }
${pu:reqSet('isCSR', false) }
<c-rt:forEach items="${groupUsersAllGroups }" var="allGroup">
<c-rt:if test="${pu:substring(allGroup.taskGroup.id, 0, 1)=='C'}">
${pu:reqSet('isCSR', true) }
</c-rt:if>
<c-rt:if test="${allGroup.taskGroup.id=='A-30-400-000'}">
${pu:reqSet('isAdmin', true) }
</c-rt:if>
</c-rt:forEach>

${pu:listAdd('groupsPara', user.username)}
${pu:listAdd('groupsPara', 'MANAGER')}
${pu:listAdd('groupsPara', 'MEMBER')}
${pu:listAdd('groupsPara', 'OBSERVER')}

${pu:reqSet('groupUserGroups', pu:customHqlQuery('select taskGroup.id from TaskGroupUser where user.username=? and (taskRole=? or taskRole=? or taskRole=?)', pu:arrayGet('groupsPara'), null, 0)) }
${pu:reqSet('groupIdStr', '') }
<c-rt:forEach items="${groupUserGroups }" var="groupId">
<c-rt:set scope="request" var="groupIdStr">
<c-rt:if test="${empty groupIdStr}">
'${groupId }'
</c-rt:if>
<c-rt:if test="${!empty groupIdStr}">
${groupIdStr },'${groupId }'
</c-rt:if>
</c-rt:set>
</c-rt:forEach>
<c-rt:if test="${empty groupIdStr}">
<c-rt:set scope="request" var="groupIdStr">
'NA--'
</c-rt:set>
</c-rt:if>
${pu:listAdd('groupsApprovePara', user.username)}
${pu:listAdd('groupsApprovePara', 'APPROVER') }
${pu:listAdd('groupsApprovePara', 'MANAGER') }
${pu:reqSet('groupUserApproveGroups', pu:customHqlQuery('select taskGroup.id from TaskGroupUser where user.username=? and (taskRole=? or taskRole=?)', pu:arrayGet('groupsApprovePara'), null, 0)) }
${pu:reqSet('groupIdApproveStr', '') }
<c-rt:forEach items="${groupUserApproveGroups }" var="groupId">
<c-rt:set scope="request" var="groupIdApproveStr">
<c-rt:if test="${empty groupIdApproveStr}">
'${groupId }'
</c-rt:if>
<c-rt:if test="${empty groupIdApproveStr}">
${groupIdApproveStr },'${groupId }'
</c-rt:if>
</c-rt:set>
</c-rt:forEach>
<c-rt:if test="${empty groupIdApproveStr}">
<c-rt:set scope="request" var="groupIdApproveStr">
'NA--'
</c-rt:set>
</c-rt:if>
<c-rt:choose>
<c-rt:when test="${empty param.orderId && empty param.memberId && empty param.priority && empty param.status && empty domainId && empty param.approveStatus && empty param.questionType && empty workOrderId && empty param.taskGroupId && empty param.creater && empty param.myTaskGroupId && empty param.responser && empty param.class1 && empty param.class2 && empty param.commonQuestionType && empty param.deliver && empty param.categoryId}">
${pu:listAdd('usernameParas','C%') }
${pu:reqSet('usernames', pu:customHqlQuery('select user.user.username from TaskGroupUser user where user.taskGroup.id like ?', pu:arrayGet('usernameParas'), null, 0) ) }
${pu:reqSet('usernameStr', '') }
<c-rt:forEach items="${usernames }" var="username">
<c-rt:if test="${usernameStr==''}">
<c-rt:set scope="request" var="usernameStr">
'SYSTEM','sms','${username }'
</c-rt:set>
</c-rt:if>
<c-rt:if test="${usernameStr!=''}">
<c-rt:set scope="request" var="usernameStr">
${usernameStr },'${username }'
</c-rt:set>
</c-rt:if>
</c-rt:forEach>


<c-rt:choose>
<c-rt:when test="${isCSR}">
<%--客服工单 --%>

${pu:reqSet('hqln1', 'from WorkOrder w where 
(
	(w.node is null and
		w.modifyUser in ('
		)}
	
${pu:reqSet('hqln2',')

	or w.createUser in (')}
	
${pu:reqSet('hqln2_1',')


	) or 
	(w.node is not null and 
		(
			((w.responseGroup like ? or w.responseGroup in (:responseGroup)) and w.approveStatus=?) 
			or 
			(w.approveGroup in (:approveGroup) and w.approveStatus=?)
		)
	)
)

order by w.status asc, w.domainId desc, w.responseGroup desc, w.approveStatus desc, w.owner desc, w.createDate desc
') }

${pu:listAdd('pvs', 'C%') }
${pu:listAdd('pvs', pu:toInteger(1)) }
${pu:listAdd('pvs', pu:toInteger(0)) }

<c-rt:set var="hqlR" scope="request">
${hqln1 }${usernameStr }${hqln2 }${usernameStr }${hqln2_1 }
</c-rt:set>
${pu:reqSet('hqlR', pu:replaceAll(hqlR, ':responseGroup', groupIdStr)) }
${pu:reqSet('hqlR', pu:replaceAll(hqlR, ':approveGroup', groupIdApproveStr)) }
${pu:reqSet('results', pu:queryByHql(hqlR, pu:arrayGet('pvs'), tp)) }
</c-rt:when>
<c-rt:otherwise>
<%--非客服工单 --%>
${pu:reqSet('hql', 'from WorkOrder w where 
(
	
	(
		(
			(w.responseGroup in (:responseGroup) and w.approveStatus=?) 
			or 
			(w.approveGroup in (:approveGroup) and w.approveStatus=?)
		)
	)
)

order by w.status asc, w.domainId desc, w.responseGroup desc, w.approveStatus desc, w.owner desc, w.createDate desc
') }

${pu:listAdd('pvs', pu:toInteger(1)) }
${pu:listAdd('pvs', pu:toInteger(0)) }

<c-rt:set var="hqlR" scope="request">
${hql }
</c-rt:set>
${pu:reqSet('hqlR', pu:replaceAll(hqlR, ':responseGroup', groupIdStr)) }
${pu:reqSet('hqlR', pu:replaceAll(hqlR, ':approveGroup', groupIdApproveStr)) }
${pu:reqSet('results', pu:queryByHql(hqlR, pu:arrayGet('pvs'), tp)) }
</c-rt:otherwise>
</c-rt:choose>
</c-rt:when>
<c-rt:otherwise>
${pu:reqSet('usernameParas', null) }
${pu:listAdd('usernameParas','C%') }
${pu:reqSet('usernames', pu:customHqlQuery('select user.username from User user where user.groupName like ?', pu:arrayGet('usernameParas'), null, 0) ) }
${pu:reqSet('usernameStr', '') }
<c-rt:forEach items="${usernames }" var="username">
<c-rt:if test="${usernameStr==''}">
<c-rt:set scope="request" var="usernameStr">
'SYSTEM','sms','${username }'
</c-rt:set>
</c-rt:if>
<c-rt:if test="${usernameStr!=''}">
<c-rt:set scope="request" var="usernameStr">
${usernameStr },'${username }'
</c-rt:set>
</c-rt:if>
</c-rt:forEach>
${pu:reqSet('user', pu:user()) }

<c-rt:choose>
<c-rt:when test="${isCSR}">
<%--客服查询 --%>
${pu:reqSet('hqlm1', 'from WorkOrder w where 
(
	(w.node is null and
		w.modifyUser in (')}
		
${pu:reqSet('hqlm2', ')
	or w.createUser in (')}

${pu:reqSet('hqlm2_1',')

	)or 
	(
		w.node is not null
		and
		((w.responseGroup like ? or w.responseGroup in(:responseGroup)) and w.approveStatus=?) or (w.approveGroup in(:approveGroup) and w.approveStatus=?)
	)
)
 ') }

${pu:reqSet('pvs', null) }
${pu:listAdd('pvs','C%')  }
${pu:listAdd('pvs', pu:toInteger(1)) }
${pu:listAdd('pvs', pu:toInteger(0)) }

<c-rt:if test="${!empty param.responser}">
${pu:reqSet('hql_0', ' and w.owner.username = ? ')}
${pu:listAdd('pvs', param.responser) }

</c-rt:if>
<%--
<c-rt:if test="${!empty param.startDate}">
${pu:reqSet('hql_1', ' and w.createDate >= ? ')}
${pu:listAdd('pvs', pu:toDate(param.startDate, 'yyyy-MM-dd')) }

</c-rt:if>
--%>
<c-rt:if test="${!empty param.startDate}">
	<c-rt:set var="startDate">
	${param.startDate } 00:00
	</c-rt:set>
${pu:reqSet('hql_1', ' and w.createDate >= ?')}
${pu:listAdd('pvs', pu:toDate(startDate, 'yyyy-MM-dd HH:mm')) }
</c-rt:if>
<%--
<c-rt:if test="${!empty param.endDate}">
${pu:reqSet('hql_2', ' and w.createDate <= ? ')}
${pu:listAdd('pvs', pu:toDate(param.endDate, 'yyyy-MM-dd')) }

</c-rt:if>
--%>
<c-rt:if test="${!empty param.endDate}">
	<c-rt:set var="endDate">
	${param.endDate } 23:59
	</c-rt:set>
${pu:reqSet('hql_2', ' and w.createDate <= ?')}
${pu:listAdd('pvs', pu:toDate(endDate, 'yyyy-MM-dd HH:mm')) }
</c-rt:if>
<c-rt:if test="${!empty param.orderId}">
${pu:reqSet('hql1', ' and w.question.extraValue[\'orderId\'].value=? ') }
${pu:listAdd('pvs', param.orderId) }
</c-rt:if>
<c-rt:if test="${!empty param.memberId}">
${pu:reqSet('hql2', ' and w.question.memberId=? ') }
${pu:listAdd('pvs', param.memberId) }
</c-rt:if>
<c-rt:if test="${!empty param.priority}"> 
${pu:reqSet('hql3', ' and w.priority=? ') }
${pu:listAdd('pvs', param.priority) }
</c-rt:if>
<c-rt:if test="${!empty param.status}"> 
<c-rt:if test="${param.status=='initNotget'}">
${pu:reqSet('hql4', ' and w.status=? and w.approveStatus=? and  (w.responseGroup=? or w.responseGroup is null) and w.owner is null ') }
${pu:listAdd('pvs', '0') }
${pu:listAdd('pvs', '1') }
${pu:listAdd('pvs', user.group.code) }
</c-rt:if>
<c-rt:if test="${param.status!='initNotget'}">
${pu:reqSet('hql4', ' and w.status=? ') }
${pu:listAdd('pvs', param.status) }
</c-rt:if>
</c-rt:if>
<c-rt:if test="${!empty domainId}"> 
${pu:reqSet('hql4_2', ' and w.domainId=? ') }
${pu:listAdd('pvs', domainId) }
</c-rt:if>
<c-rt:if test="${!empty param.approveStatus}"> 
${pu:reqSet('hql4_3', ' and w.approveStatus=? ') }
${pu:listAdd('pvs', param.approveStatus) }
</c-rt:if>
<c-rt:if test="${!empty param.questionType}"> 
<c-rt:if test="${param.questionType=='CommonQuestion_product'}">
<c-rt:set var="hql4_4" scope="request">
 and w.question.type=? and w.question.extraValue['isProductQAA'].value=? 
</c-rt:set>
${pu:listAdd('pvs', 'CommonQuestion') }
${pu:listAdd('pvs', 'true') }

</c-rt:if>
<c-rt:if test="${param.questionType=='CommonQuestion'}">
<c-rt:set var="hql4_4" scope="request">
 and w.question.type=? and w.question.extraValue['isProductQAA'].value!=? 
</c-rt:set>
${pu:listAdd('pvs', 'CommonQuestion') }
${pu:listAdd('pvs', 'true') }

</c-rt:if>
<c-rt:if test="${param.questionType!='CommonQuestion_product' && param.questionType!='CommonQuestion'}">
${pu:reqSet('hql4_4', ' and w.question.type=? ') }
${pu:listAdd('pvs', param.questionType) }
</c-rt:if>
</c-rt:if>
<c-rt:if test="${!empty param.workOrderId}">
${pu:reqSet('hql4_5', ' and w.id=? ' )}
${pu:listAdd('pvs', param.workOrderId) }
</c-rt:if>
<c-rt:if test="${!empty param.taskGroupId}">
${pu:reqSet('hql_taskGroupId', ' and w.createGroup=? ')}
${pu:listAdd('pvs', param.taskGroupId) }
</c-rt:if>
<c-rt:if test="${!empty param.createUser}">
${pu:reqSet('hql_createUser', ' and w.createUser=? ')}
${pu:listAdd('pvs', param.createUser) }
</c-rt:if>
<c-rt:if test="${!empty param.myTaskGroupId}">
${pu:reqSet('hql_myTaskGroupId', ' and w.responseGroup=? ')}
${pu:listAdd('pvs', param.myTaskGroupId) }
</c-rt:if>
<c-rt:if test="${!empty param.responser}">
${pu:reqSet('hql_responser', ' and w.owner.username=? ')}
${pu:listAdd('pvs', param.responser) }
</c-rt:if>
<c-rt:if test="${!empty param.class1}">
<c-rt:set var="hql_class1" scope="request">
 and w.question.extraValue['class1'].value=? 
</c-rt:set>
${pu:listAdd('pvs', param.class1) }
</c-rt:if>
<c-rt:if test="${!empty param.class2}">
<c-rt:set var="hql_class2" scope="request">
 and w.question.extraValue['class2'].value=? 
 </c-rt:set>
${pu:listAdd('pvs', param.class2) }
</c-rt:if>
<c-rt:if test="${!empty param.commonQuestionType}">
<c-rt:set var="hql_commonQuestionType" scope="request">
 and w.question.extraValue['commonQuestionType'].value=? 
</c-rt:set>
${pu:listAdd('pvs', param.commonQuestionType) }
</c-rt:if>

<c-rt:if test="${!empty param.deliver}">
${pu:reqSet('hql_deliver', ' and w.question.deliver=? ')}
${pu:listAdd('pvs', param.deliver) }
</c-rt:if>
<c-rt:if test="${!empty param.categoryId}">
${pu:reqSet('hql_categoryId', ' and w.question.category=? ')}
${pu:listAdd('pvs', param.categoryId) }
</c-rt:if>
${pu:reqSet('hql5', ' order by w.status asc, w.domainId desc, w.responseGroup desc, w.approveStatus desc, w.owner desc, w.createDate desc') }
<c-rt:set var="hqlR" scope="request">
${hqlm1 }${usernameStr }${hqlm2 }${usernameStr }${hqlm2_1 }${hql_0 }${hql_1 }${hql_2 }${hql1 }${hql2 }${hql3 }${hql4 }${hql4_2 }${hql4_3 }${hql4_4 }${hql4_5 }${hql_taskGroupId }${hql_createUser }${hql_myTaskGroupId }${hql_responser }${hql_class1 }${hql_class2 }${hql_commonQuestionType }${hql_deliver }${hql_categoryId }${hql5 }
</c-rt:set>

${pu:reqSet('hqlR', pu:replaceAll(hqlR, ':responseGroup', groupIdStr)) }
${pu:reqSet('hqlR', pu:replaceAll(hqlR, ':approveGroup', groupIdApproveStr)) }
${pu:reqSet('results', pu:queryByHql(hqlR, pu:arrayGet('pvs'), tp)) }

</c-rt:when>
<c-rt:otherwise>
<%--非客服查询 --%>
${pu:reqSet('hql', 'from WorkOrder w where (w.responseGroup in (:responseGroup) or w.approveGroup in (:approveGroup)) ') }
${pu:reqSet('pvs', null) }

<c-rt:if test="${!empty param.startDate}">
	<c-rt:set var="startDate">
	${param.startDate } 00:00
	</c-rt:set>
${pu:reqSet('hql01', ' and w.createDate >= ?')}
${pu:listAdd('pvs', pu:toDate(startDate, 'yyyy-MM-dd HH:mm')) }
</c-rt:if>
<c-rt:if test="${!empty param.endDate}">
	<c-rt:set var="endDate">
	${param.endDate } 23:59
	</c-rt:set>
${pu:reqSet('hql02', ' and w.createDate <= ?')}
${pu:listAdd('pvs', pu:toDate(endDate, 'yyyy-MM-dd HH:mm')) }
</c-rt:if>
<c-rt:if test="${!empty param.orderId}">
${pu:reqSet('hql1', ' and w.question.extraValue[\'orderId\'].value=? ') }
${pu:listAdd('pvs', param.orderId) }
</c-rt:if>
<c-rt:if test="${!empty param.memberId}">
${pu:reqSet('hql2', ' and w.question.memberId=? ') }
${pu:listAdd('pvs', param.memberId) }
</c-rt:if>
<c-rt:if test="${!empty param.priority}"> 
${pu:reqSet('hql3', ' and w.priority=? ') }
${pu:listAdd('pvs', param.priority) }
</c-rt:if>
<c-rt:if test="${!empty param.status}"> 
<c-rt:if test="${param.status=='initNotget'}">
${pu:reqSet('hql4', ' and w.status=? and w.approveStatus=? and  (w.responseGroup=? or w.responseGroup is null) and w.owner is null ') }
${pu:listAdd('pvs', '0') }
${pu:listAdd('pvs', '1') }
${pu:listAdd('pvs', user.group.code) }
</c-rt:if>
<c-rt:if test="${param.status!='initNotget'}">
${pu:reqSet('hql4', ' and w.status=? ') }
${pu:listAdd('pvs', param.status) }
</c-rt:if>
</c-rt:if>
<c-rt:if test="${!empty domainId}"> 
${pu:reqSet('hql4_2', ' and w.domainId=? ') }
${pu:listAdd('pvs', domainId) }
</c-rt:if>
<c-rt:if test="${!empty param.approveStatus}"> 
${pu:reqSet('hql4_3', ' and w.approveStatus=? ') }
${pu:listAdd('pvs', param.approveStatus) }
</c-rt:if>
<c-rt:if test="${!empty param.questionType}"> 
<c-rt:if test="${param.questionType=='CommonQuestion_product'}">
<c-rt:set var="hql4_4" scope="request">
 and w.question.type=? and w.question.extraValue['isProductQAA'].value=? 
</c-rt:set>
${pu:listAdd('pvs', 'CommonQuestion') }
${pu:listAdd('pvs', 'true') }

</c-rt:if>
<c-rt:if test="${param.questionType!='CommonQuestion_product'}">
${pu:reqSet('hql4_4', ' and w.question.type=? ') }
${pu:listAdd('pvs', param.questionType) }
</c-rt:if>
</c-rt:if>
<c-rt:if test="${!empty param.workOrderId}">
${pu:reqSet('hql4_5', ' and w.id=? ' )}
${pu:listAdd('pvs', param.workOrderId) }
</c-rt:if>
<c-rt:if test="${!empty param.taskGroupId}">
${pu:reqSet('hql_taskGroupId', ' and w.createGroup=? ')}
${pu:listAdd('pvs', param.taskGroupId) }
</c-rt:if>
<c-rt:if test="${!empty param.createUser}">
${pu:reqSet('hql_createUser', ' and w.createUser=? ')}
${pu:listAdd('pvs', param.createUser) }
</c-rt:if>
<c-rt:if test="${!empty param.myTaskGroupId}">
${pu:reqSet('hql_myTaskGroupId', ' and w.responseGroup=? ')}
${pu:listAdd('pvs', param.myTaskGroupId) }
</c-rt:if>
<c-rt:if test="${!empty param.responser}">
${pu:reqSet('hql_responser', ' and w.owner.username=? ')}
${pu:listAdd('pvs', param.responser) }
</c-rt:if>
<c-rt:if test="${!empty param.class1}">
<c-rt:set var="hql_class1" scope="request">
 and w.question.extraValue['class1'].value=? 
</c-rt:set>
${pu:listAdd('pvs', param.class1) }
</c-rt:if>
<c-rt:if test="${!empty param.class2}">
<c-rt:set var="hql_class2" scope="request">
 and w.question.extraValue['class2'].value=? 
 </c-rt:set>
${pu:listAdd('pvs', param.class2) }
</c-rt:if>
<c-rt:if test="${!empty param.commonQuestionType}">
<c-rt:set var="hql_commonQuestionType" scope="request">
 and w.question.extraValue['commonQuestionType'].value=? 
</c-rt:set>
${pu:listAdd('pvs', param.commonQuestionType) }
</c-rt:if>

<c-rt:if test="${!empty param.deliver}">
${pu:reqSet('hql_deliver', ' and w.question.deliver=? ')}
${pu:listAdd('pvs', param.deliver) }
</c-rt:if>
<c-rt:if test="${!empty param.categoryId}">
${pu:reqSet('hql_categoryId', ' and w.question.category=? ')}
${pu:listAdd('pvs', param.categoryId) }
</c-rt:if>
${pu:reqSet('hql5', ' order by w.status asc, w.domainId desc, w.responseGroup desc, w.approveStatus desc, w.owner desc, w.createDate desc') }
<c-rt:set var="hqlR" scope="request">
${hql }${hql01 }${hql02 }${hql1 }${hql2 }${hql3 }${hql4 }${hql4_2 }${hql4_3 }${hql4_4 }${hql4_5 }${hql_taskGroupId }${hql_createUser }${hql_myTaskGroupId }${hql_responser }${hql_class1 }${hql_class2 }${hql_commonQuestionType }${hql_deliver }${hql_categoryId }${hql5 }
</c-rt:set>
${pu:reqSet('hqlR', pu:replaceAll(hqlR, ':responseGroup', groupIdStr)) }
${pu:reqSet('hqlR', pu:replaceAll(hqlR, ':approveGroup', groupIdApproveStr)) }
${pu:reqSet('results', pu:queryByHql(hqlR, pu:arrayGet('pvs'), tp)) }

</c-rt:otherwise>
</c-rt:choose>

</c-rt:otherwise>
</c-rt:choose>
<c-rt:set var="hqlUser" value="from User where group.code like ?"/>
<c-rt:set var="pvsUser" value="${pu:addToList('parasUser', 'C%')}"/>
<c-rt:set var="users" value="${pu:queryByHql(hqlUser, pvsUser, null)}"/>
${pu:reqSet('menu', pu:get('com.yaodian100.core.menu.entity.Menu', 'WorkOrder.status')) }
<br />
<h1>工单管理
</h1>
<%--
${pu:reqSet('q', pu:get('com.yaodian100.crm.cs.entity.Question', '8a8080c72741d923012741e33fb80002')) }
<c-rt:forEach items="${q.answers }" var="a">
${a.id }<br/>
</c-rt:forEach>
--%>
<form name="theForm" method="post">
<input type="hidden" name="iamlazy" id="iamlazy" value="list"/>
<table>
<%--
<c-rt:if test="${pu:isCRMManager(pu:username())}">
<tr>
<td>处理人：<select name="responser" id="responser">
	<option value="">请选择</option>
	<c-rt:forEach items="${users }" var="user">
	<option value="${user.username }" ${user.username==param.responser?'selected="selected"':'' }>${user.username }</option>
	</c-rt:forEach>
	</select>
</td>
<td></td>
</tr>
</c-rt:if>
 --%>
<tr>
<td>
订单编号：<input size="13" type="text" name="orderId" value="${param.orderId }"/>
会员编号：<input size="10" type="text" name="memberId" value="${param.memberId }"/>
</td><td>
</td>
</tr>
<tr>
<td>
时间区间(yyyy-MM-dd)：
<input type="text" name="startDate" id="startDate" value="${param.startDate }"/>
~
<input type="text" name="endDate" id="endDate" value="${param.endDate }"/>
工单编号：<input size="10" type="text" id="workOrderId" name="workOrderId" value="${param.workOrderId }"/>
问题单编号：<input size="16" type="text" name="domainId" value="${domainId}"/>
</td>
<td></td>
</tr>
<tr>
<td>
<table><tr><td>
${pu:reqSet('taskGroups', pu:queryByHql('from TaskGroup order by id asc', null, null)) }
建立人分组：
</td>
<td>
<select name="taskGroupId" onchange="doAR('/ecadmin/cs/taskGroup/page.do?iamlazy=taskGroupUsers&taskGroupId='+this.value+'&columnName=createUser&username=${param.createUser }', 'createUser')">
<option value="">请选择</option>
<c-rt:forEach items="${taskGroups }" var="taskGroup">
<option value="${taskGroup.id }" <c-rt:if test="${taskGroup.id==param.taskGroupId }">selected="selected"</c-rt:if>>${taskGroup.name }</option>
</c-rt:forEach>
</select>
</td>
<td>
建立人：
</td>
<td>
<div id="createUser" class="float:left"><select name="createUser"></select></div>
</td>
<td>
${pu:listAdd('myTaskGroupParams', pu:user().username) }
${pu:reqSet('myTaskGroups', pu:queryByHql('from TaskGroupUser where user.username=? order by id asc', pu:arrayGet('myTaskGroupParams'), null)) }
处理分组：
</td>
<td>
<select name="myTaskGroupId" onchange="doAR('/ecadmin/cs/taskGroup/page.do?iamlazy=taskGroupUsers&taskGroupId='+this.value+'&columnName=responser&username=${param.responser }', 'responser')">
<option value="">请选择</option>
<c-rt:forEach items="${myTaskGroups}" var="myTaskGroup">
<option value="${myTaskGroup.taskGroup.id }" <c-rt:if test="${myTaskGroup.taskGroup.id==param.myTaskGroupId}">selected="selected"</c-rt:if>>${myTaskGroup.taskGroup.name }</option>
</c-rt:forEach>
</select>
</td>
<td>
处理人：
</td>
<td width="200">
<div id="responser" style="float:left"><select name="responser"></select></div>
</td></tr></table>
</td>
</tr>
<tr>
<td>
<script>
$(function(){
	doAR('/ecadmin/cs/page.do?iamlazy=cqTypeList&class1=${param.class1}', 'class1Zone');
	doAR('/ecadmin/cs/page.do?iamlazy=subTypeList&class2=${param.class2}&parentId=${param.class1}', 'class2Zone');
	doAR('/ecadmin/cs/page.do?iamlazy=level3List&commonQuestionType=${param.commonQuestionType}&parentId=${param.class2}', 'commonQuestionTypeZone');
});

</script>
<table><tr><td>问题大类：</td><td><div id="class1Zone"><select name="class1"></select></div></td>
<td>问题中类：</td><td><span id="class2Zone"><select name="class2"></select></span></td>
<td>问题小类：</td><td><span id="commonQuestionTypeZone"><select name="commonQuestionType"></select></span></td></tr></table>
</td>
</tr>
<tr>
<td>
${pu:reqSet('logisticProviders', pu:queryByHql('from LogisticProvider order by id asc', null, null)) }
配送商：<select name="deliver">
<option value="">请选择</option>
<c-rt:forEach items="${logisticProviders }" var="lp">
<option value="${lp.id }" <c-rt:if test="${lp.id==param.deliver }">selected="selected"</c-rt:if>>${lp.name }</option>
</c-rt:forEach>
</select>
商品线：<select name="categoryId">
<option value="">请选择</option>
<c-rt:forEach items="${pu:listCategoryLevel0()}" var="category">
<option value="${category.id }" <c-rt:if test="${category.id==param.categoryId}">selected="selected"</c-rt:if>>${category.name }</option>
</c-rt:forEach>
</select>
</td>
</tr>
<tr>
<td>
处理等级：<select name="priority">
<option value="">请选择</option>
<option value="0" <c-rt:if test="${param.priority == '0'}">selected="selected"</c-rt:if>>函件</option>
<option value="1" <c-rt:if test="${param.priority == '1'}">selected="selected"</c-rt:if>>一般件</option>
<option value="2" <c-rt:if test="${param.priority == '2'}">selected="selected"</c-rt:if>>急件</option>
<option value="3" <c-rt:if test="${param.priority == '3'}">selected="selected"</c-rt:if>>特急件</option>
</select>
状态：
<select name="status">
<option value="">请选择</option>
<option value="initNotget" <c-rt:if test="${'initNotget'==param.status }">selected="selected"</c-rt:if>>初始－未取得</option>
<c-rt:forEach items="${menu.options}" var="option">
<option value="${option.value.code }" <c-rt:if test="${option.value.code==param.status }">selected="selected"</c-rt:if>>${option.value.name }</option>
</c-rt:forEach>
</select>
审核状态：
<select name="approveStatus">
<option value="">请选择</option>
<option value="0" <c-rt:if test="${param.approveStatus=='0' }">selected="selected"</c-rt:if>>待审核</option>
<option value="1" <c-rt:if test="${param.approveStatus=='1' }">selected="selected"</c-rt:if>>已核可</option>
<option value="2" <c-rt:if test="${param.approveStatus=='2' }">selected="selected"</c-rt:if>>已注销</option>

</select>
问题类型：
${pu:reqSet('questionTypes', pu:queryByHql('from QuestionType', null,null)) }
<select name="questionType">
<option value="">请选择</option>
<option value="CommonQuestion_product" <c-rt:if test="${param.questionType=='CommonQuestion_product' }">selected="selected"</c-rt:if>>商品问答</option>

<c-rt:forEach items="${questionTypes}" var="qt">
<option value="${qt.name }" <c-rt:if test="${param.questionType==qt.name}">selected="selected"</c-rt:if>>${qt.description }</option>
</c-rt:forEach>
</select>
</td>
<td></td>
</tr>
<tr>
<td><input type="button" id="searchWorkOrder" value="搜索"/></td>
<td></td>
</tr>
</table>
</form>
<table class="tb-2" width="100%">
			<tr>
				<th style="width:40px" width="40"><table><tr><td>ID</td></tr></table></th>
				
				<th style="width:120px">
				<table width="100%">
				<tr>
				<th style="border-bottom:1px solid #F80;">问题单编号</th>
				</tr>
				<tr>
				<th>订单编号</th>
				</tr>
				</table>
				
				
				</th>
				
				
				
				<th style="width:70px">
				<table width="100%">
				<tr>
				<th style="border-bottom:1px solid #F80;">处理等级</th>
				</tr>
				<tr>
				<th>类型</th>
				</tr>
				</table>
				</th>
				<th style="width:40px">状态</th>
				
				<th style="width:100px">
				<table width="100%">
				<tr>
				<th style="border-bottom:1px solid #F80;">处理人</th>
				</tr>
				<tr>
				<th>处理群组</th>
				</tr>
				</table>
				</th>
				
				<th style="width:50px">
				<table width="100%">
				<tr>
				<th style="border-bottom:1px solid #F80;">审核群组</th>
				</tr>
				<tr>
				<th>审核状态</th>
				</tr>
				</table>
				</th>
				
				<th style="width:100px">
				<table width="100%">
				<tr>
				<th style="border-bottom:1px solid #F80;">建立人</th>
				</tr>
				<tr>
				<th>建立人群組</th>
				</tr>
				</table>
				</th>
				
				<th style="width:90px">
				<table width="100%">
				<tr>
				<th style="border-bottom:1px solid #F80;">建立日期</th>
				</tr>
				<tr>
				<th>转单回覆日期</th>
				</tr>
				</table>
				</th>
				
				<th style="width:500px">
				<table width="100%">
				<tr>
				<th style="border-bottom:1px solid #F80;">问题说明</th>
				</tr>
				<tr>
				<th>前单说明</th>
				</tr>
				</table>
				</th>
				
			</tr>


			
			<c-rt:forEach items="${results}" var="result" varStatus="rows_index">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffffff"
			</c-rt:set>
			<c-rt:if test="${pu:subDateInHour(pu:currentDate(), result.createDate)>24}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#aaffff"
			</c-rt:set>
			</c-rt:if>
			<c-rt:if test="${pu:subDateInHour(pu:currentDate(), result.createDate)>48}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffffaa"
			</c-rt:set>
			</c-rt:if>
			<c-rt:if test="${pu:subDateInHour(pu:currentDate(), result.createDate)>72}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffaaff"
			</c-rt:set>
			</c-rt:if>
			<c-rt:if test="${result.status==2}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffffff"
			</c-rt:set>
			</c-rt:if>
			<tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''}" ${theStyle }>
					<th>
					<table style="cellspacing:0px;cellpadding:0px"><tr><td style="padding:0px">	
					${result.id }<br/>
					</td></tr>
					<%--<c-rt:if test="${result.status!='2' &&((empty result.owner && !empty result.node.responseGroup) || (pu:isCRMManager(pu:username()) && result.owner.username!=pu:username()) || (result.owner==null))}">--%>
					<c-rt:if test="${result.status=='0' }">
					<c-rt:if test="${!empty result.responseGroup}">
					${pu:reqSet('rtgPara', null) }
					${pu:listAdd('rtgPara', user.username) }
					${pu:listAdd('rtgPara', result.responseGroup) }
					${pu:reqSet('responseTaskGroup', pu:queryByHql('from TaskGroupUser where user.username=? and taskGroup.id=?', pu:arrayGet('rtgPara'),null))   }
					<c-rt:if test="${responseTaskGroup[0].taskRole=='MANAGER' || responseTaskGroup[0].taskRole=='MEMBER'}">
					<c-rt:forEach items="${groupUsersAllGroups}" var="allGroup">
						<c-rt:if test="${allGroup.taskGroup.id==result.responseGroup}">
						<tr><td  style="padding:0px">
						<c-rt:choose>
							<c-rt:when test="${empty result.owner.username}">
								<div style="border:1px solid #aaa;float:left;margin-bottom:0px;padding:0 5px;width:30px"><a href="<c-rt:url value="/workOrder/get.do?refreshZone=main&id=${result.id}&fromManage=true"/>" target="_blank">取得</a></div><br/>
							</c-rt:when>
							<c-rt:otherwise>
							<c-rt:if test="${result.owner.username!=user.username}">
								<div style="border:1px solid #aaa;float:left;margin-bottom:0px;padding:0 5px;width:30px"><a href="<c-rt:url value="/workOrder/get.do?refreshZone=main&id=${result.id}&fromManage=true"/>" target="_blank">代结</a></div><br/>
							</c-rt:if>
							<c-rt:if test="${result.owner.username==user.username}">
								<div style="border:1px solid #aaa;float:left;margin-bottom:0px;padding:0 5px;width:30px"><a href="<c-rt:url value="/cs/page.do?iamlazy=viewQuestion&id=${result.id}"/>" target="_blank">处理</a></div><br/>
							</c-rt:if>
							</c-rt:otherwise>
						</c-rt:choose>
						</td></tr>
					</c-rt:if>
					</c-rt:forEach>
					</c-rt:if> 
					</c-rt:if>
					
					<c-rt:if test="${empty result.responseGroup && result.status=='0'}">
						<c-rt:if test="${isCSR}">
							<c-rt:set var="tempText" value=""/>
							<c-rt:forEach items="${groupUsersAllGroups}" var="allGroup">
								<c-rt:if test="${pu:substring(allGroup.taskGroup.id, 0, 1)=='C' and (allGroup.taskRole=='MANAGER' or allGroup.taskRole=='MEMBER')}">
								<tr><td  style="padding:0px">
									<c-rt:if test="${result.owner.username!=user.username and empty tempText}">
										<div style="border:1px solid #aaa;float:left;margin-bottom:0px;padding:0 5px;width:30px"><a href="<c-rt:url value="/workOrder/get.do?refreshZone=main&id=${result.id}&fromManage=true"/>" target="_blank">取得</a></div><br/>
										<c-rt:set var="tempText" value="取得"/>
									</c-rt:if>
									<c-rt:if test="${result.owner.username==user.username and empty tempText}">
										<div style="border:1px solid #aaa;float:left;margin-bottom:0px;padding:0 5px;width:30px"><a href="<c-rt:url value="/cs/page.do?iamlazy=viewQuestion&id=${result.id}"/>" target="_blank">处理</a></div><br/>
										<c-rt:set var="tempText" value="处理"/>
									</c-rt:if>
								</td></tr>
								</c-rt:if>
							</c-rt:forEach>
						</c-rt:if>
					</c-rt:if>
					</c-rt:if>
					<c-rt:if test="${pu:isCRMManager(pu:username()) || user.group.code=='C.02'}">
					<tr><td  style="padding:0px">
					<div style="border:1px solid #aaa;float:left;margin-bottom:0px;padding:0 5px;width:30px"><a href="javascript:doAR('<%=application.getContextPath() %>/workOrder/page.do?iamlazy=trace&AJAX=true&refreshZone=main&id=${result.id}', 'dialog');openDialog('trace', '', 700, 300)">追踪</a></div><br/>
					</td></tr>
					</c-rt:if>
					<c-rt:if test="${(isAdmin || isCSR) && (!empty result.owner || (empty result.owner && result.status==2)) && ( result.status!=1) }">
					<tr><td  style="padding:0px">
					<div style="border:1px solid #aaa;float:left;margin-bottom:0px;padding:0 5px;width:30px"><a target="_blank" href="/ecadmin/cs/page.do?iamlazy=question&forward=newOrder&questionType=${result.question.type.name }&formType=workOrder&questionID=${result.question.id }&workOrderId=${result.id}">成立工单</a></div><br/>
					</td></tr>
					</c-rt:if>
					<c-rt:if test="${!empty result.approveGroup && result.approveStatus==0 && result.status!=9 && ( empty result.approver || (!empty result.approver && result.approver==user.username))}">
					${pu:reqSet('theAGPara', null) }
					${pu:listAdd('theAGPara', user.username) }
					${pu:listAdd('theAGPara', result.approveGroup) }
					${pu:listAdd('theAGPara', 'MANAGER') }
					${pu:listAdd('theAGPara', 'MEMBER') }
					${pu:reqSet('theAGHql', 'from TaskGroupUser where user.username=? and taskGroup.id =? and (taskRole=? or taskRole=?)') }

					${pu:reqSet('theApproveGroups', pu:queryByHql(theAGHql,pu:arrayGet('theAGPara'), null)) }
					<c-rt:if test="${!empty theApproveGroups}">
					<tr><td  style="padding:0px">
					<div style="border:1px solid #aaa;float:left;margin-bottom:0px;padding:0 5px;width:30px"><a href="<c-rt:url value="/workOrder/toApprove.do?id=${result.id}"/>" target="_blank">前往审核</a></div><br/>
					</td></tr>
					</c-rt:if>
					
					</c-rt:if>
					<tr><td  style="padding:0px">
					<div style="border:1px solid #aaa;float:left;margin-bottom:0px;padding:0 5px;width:30px"><a href="<c-rt:url value="/cs/page.do?iamlazy=viewQuestion&id=${result.id}"/>" target="_blank">明细</a></div><br/>
					</td></tr></table>
					</th>
					<td width="120">
					<table width="100%">
					<tr>
					<td style="border-bottom:1px solid #ddd;">${result.question.id }</td>
					</tr>
					<tr>
					<td style="word-wrap: break-word;word-break: break-all;">${result.question.extraValue['orderId'].value }</td>
					</tr>
					</table>
					</td>
					
					
					
					
					<td width="50">
					<table width="100%">
					<tr><td style="border-bottom:1px solid #ddd;"><c-rt:if test="${result.priority==0}">
					函件
					</c-rt:if>
					<c-rt:if test="${result.priority==1}">
					一般件
					</c-rt:if>
					<c-rt:if test="${result.priority==2}">
					急件
					</c-rt:if>
					<c-rt:if test="${result.priority==3}">
					特急件
					</c-rt:if></td></tr>
					<tr><td>
					<c-rt:if test="${result.question.type.name=='CommonQuestion' }">
						<c-rt:if test="${result.question.extraValue['isProductQAA'].value=='true' }">
							商品问答
						</c-rt:if>
						<c-rt:if test="${result.question.extraValue['isProductQAA'].value!='true' }">
							客服问答
						</c-rt:if>
					</c-rt:if>
					<c-rt:if test="${result.question.type.name!='CommonQuestion' }">
					${result.question.type.description }
					</c-rt:if>
					
					</td></tr>
					</table>
					
					</td>
					
					<td width="40">
					${pu:menuOption('WorkOrder.status', pu:toString(result.status)).name }
					</td>
					
					<td width="100">
					<table width="100%"><tr><td style="border-bottom:1px solid #ddd;"><c-rt:choose>
						<c-rt:when test="${result.status!='2' && pu:isCRMManager(pu:username()) && (isCSR || empty result.node.responseGroup)}">
						<select name="user" onchange="doAR('<%=application.getContextPath() %>/workOrder/assign.do?AJAX=true&refreshZone=main&id=${result.id}&username='+this.value, 'main')">
							<option value="">please select</option>
						<c-rt:forEach items="${users}" var="user">
							<option value="${user.username }" <c-rt:if test="${user.username==result.owner.username }">selected="selected"</c-rt:if>>${user.username }</option>
						</c-rt:forEach>
						</select>
						</c-rt:when>
						<c-rt:otherwise>
						<c-rt:if test="${!empty result.owner.username}">
						${result.owner.username}
						</c-rt:if>
						</c-rt:otherwise>
					</c-rt:choose>
					</td></tr>
					<tr><td>
					<c-rt:if test="${!empty result.responseGroup}">
					${pu:get('com.yaodian100.crm.workorder.entity.TaskGroup', result.responseGroup).name }(${result.responseGroup })
					</c-rt:if>
					</td></tr>
					</table>
					
					</td>
					
					<td width="50">
					<table width="100%"><tr><td style="border-bottom:1px solid #ddd;">
					<c-rt:if test="${!empty result.approveGroup}">
					${pu:get('com.yaodian100.crm.workorder.entity.TaskGroup', result.approveGroup).name }(${result.approveGroup })
					</c-rt:if></td></tr><tr>
					<td>
					<c-rt:if test="${result.approveStatus==0 }">
					待审核
					</c-rt:if>
					<c-rt:if test="${result.approveStatus==1 }">
					已核可
					</c-rt:if>
					<c-rt:if test="${result.approveStatus==2 }">
					已注销
					</c-rt:if>
					</td></tr></table>
					
					</td>
					
					<td width="100">
					<table width="100%"><tr><td style="border-bottom:1px solid #ddd;">${result.createUser }</td></tr>
					<tr><td>
					${pu:reqSet('createUser', pu:get('com.yaodian100.core.admin.entity.User', result.createUser)) }
					<c-rt:if test="${!empty createUser}">
					${createUser.group.description }(${createUser.group.code })
					</c-rt:if>
					</td></tr>
					</table>
					</td>
					
					<td width="80">
					<table width="100%"><tr><td style="border-bottom:1px solid #ddd;"><fmt-rt:formatDate value="${result.createDate }" pattern="yyyy/MM/dd HH:mm"/></td></tr>
					<tr><td>${pu:reqSet('replyHql', 'from WorkOrder where parent.id=?') }
					${pu:reqSet('replyList', null) }
					${pu:listAdd('replyList', result.id) }
					${pu:reqSet('replyWorkOrder', pu:queryByHql(replyHql, pu:arrayGet('replyList'), null)) }
					
					<c-rt:if test="${!empty replyWorkOrder}">
					<c-rt:if test="${!empty replyWorkOrder[0].finishTime}">
					<fmt-rt:formatDate value="${replyWorkOrder[0].finishTime}" pattern="yyyy-MM-dd HH:mm"/>
					</c-rt:if>
					<c-rt:if test="${empty replyWorkOrder[0].finishTime}">
					<b>尚未回覆</b>
					</c-rt:if>
					</c-rt:if>
					<c-rt:if test="${empty replyWorkOrder}">
					未转单
					</c-rt:if></td></tr>
					</table>
					
					</td>
					
					<td >
					<table width="100%">
					<tr><td style="border-bottom:1px solid #ddd;word-wrap: break-word;word-break: break-all;">${result.question.description }</td></tr>
					<tr><td style="word-wrap: break-word;word-break: break-all;">
					${result.comment }
					</td></tr>
					</table>
					
					</td>
				</tr>

			</c-rt:forEach>

	</table>
<c-rt:set var="url">
<%=application.getContextPath() %>/workOrder/page.do
</c-rt:set>
<pageable:Pageable url="${url}" escapeparams="iamlazy,AJAX,refreshZone" parameter="iamlazy=list&refreshZone=main" formname="woForm" key="tpp"></pageable:Pageable>
<table width="100%">
<tr>
<td align="right">
${pu:reqSet('currentPage', param.tpp_pageable_currentPage) }
<c-rt:if test="${empty param.tpp_pageable_currentPage}">
${pu:reqSet('currentPage', 1) }
</c-rt:if>
目前在第${currentPage }页, 资料共${tp.totalRecords }笔</td>
</tr>
</table>
</c-rt:if>
<c-rt:if test="${(!empty param.fromOrder)}">
<c-rt:set var="tp" value="${pu:pageableTag('tpp', 20, 10)}"/>
${pu:reqSet('hql', 'from WorkOrder w where ')}
${pu:reqSet('hql2', '') }


<c-rt:if test="${!empty param.memberId}">
${pu:reqSet('hql1', ' w.question.memberId=? ')}
${pu:listAdd('list', param.memberId) }
</c-rt:if>
<c-rt:if test="${!empty param.orderId}">
${pu:listAdd('list', param.orderId) }
<c-rt:if test="${!empty hql1}">
${pu:reqSet('hql2', ' and w.question.extraValue[\'orderId\'].value=? ')}
</c-rt:if>
<c-rt:if test="${empty hql1}">
${pu:reqSet('hql2', ' w.question.extraValue[\'orderId\'].value=? ')}
</c-rt:if>
</c-rt:if>
<c-rt:if test="${!empty param.startDate}">
${pu:listAdd('list', pu:toDate(param.startDate, 'yyyy-MM-dd')) }
${pu:reqSet('hql3', ' and w.createDate >=?') }
</c-rt:if>
<c-rt:if test="${!empty param.endDate}">
${pu:listAdd('list', pu:toDate(param.endDate, 'yyyy-MM-dd')) }
${pu:reqSet('hql4', ' and w.createDate <=?') }
</c-rt:if>
${pu:reqSet('hql5', ' and w.question.orgQuestionId is null and w.parent is null') }
${pu:reqSet('hqlOrder', ' order by w.createDate desc')}
<c-rt:set var="hqlR">
${hql }${hql1 }${hql2 }${hql3 }${hql4 }${hql5 }${hqlOrder }
</c-rt:set>

${pu:reqSet('results', pu:queryByHql(hqlR, pu:arrayGet('list'), tp)) }

<h1>工单列表

</h1>
<form name="theForm">
<input type="hidden" name="iamlazy" id="iamlazy" value="list"/>
<table>
<tr>
<td>
<input type="hidden" name="fromOrder" value="true"/>
会员编号：${param.memberId }<input type="hidden" name="memberId" value="${param.memberId }"/><br/>
订单编号：${param.orderId }<input type="hidden" name="orderId" value="${param.orderId}"/>
</td>
</tr>
<tr>
<td>日期区间：<input type="text" name="startDate" id="startDate" value="${param.startDate }"/>
~<input type="text" name="endDate" id="endDate" value="${param.endDate }"/>
</td>
</tr>
<tr>
<td>
<input type="button" id="searchWorkOrder" value="搜索"/>
</td>
</tr>
</table>
</form>
<table width="100%" class="ntb" rules="groups">
		<thead>
			<tr>
				<th></th>
				<th width="30"></th>
				<th>ID</th>
				<th>问题单编号</th>
				<th>订单编号</th>
				
				<th>问题说明</th>
				<th>前单说明</th>
				<th>处理等级</th>
				<th>状态</th>
				<th>类型</th>
				<th>处理人</th>
				<th>处理群组</th>
				<th>审核群组</th>
				<th>审核状态</th>
				<th>建立日期</th>
				<th>转单回覆日期</th>
			</tr>
		</thead>
		
			<c-rt:forEach items="${results}" var="result">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffffff"
			</c-rt:set>
			<c-rt:if test="${pu:subDateInHour(pu:currentDate(), result.createDate)>24}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#aaffff"
			</c-rt:set>
			</c-rt:if>
			<c-rt:if test="${pu:subDateInHour(pu:currentDate(), result.createDate)>48}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffffaa"
			</c-rt:set>
			</c-rt:if>
			<c-rt:if test="${pu:subDateInHour(pu:currentDate(), result.createDate)>72}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffaaff"
			</c-rt:set>
			</c-rt:if>
			<c-rt:if test="${result.status==2}">
			<c-rt:set var="theStyle" scope="request">
			style="background-color:#ffffff"
			</c-rt:set>
			</c-rt:if>
			<tbody style="border:2px solid #000;">
				${pu:reqSet('wosPara', null) }
				${pu:listAdd('wosPara', result.question.id) }
			
				${pu:reqSet('wos', pu:queryByHql('from WorkOrder where domainId=? and parent is not null order by createDate desc', pu:arrayGet('wosPara'), null)) }
				${pu:reqSet('woList', null) }
				<c-rt:forEach items="${wos }" var="wo">
					${pu:listAdd('woList', wo) }
				</c-rt:forEach>
				${pu:listAdd('woList', result) }
				<c-rt:forEach items="${woList }" var="result">
				<tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''}" ${theStyle }>
				<td></td>
				<td>

<a href="/ecadmin/cs/page.do?iamlazy=viewQuestion&id=${result.id }">明细</a>

				</td>
				<td>${result.id }</td>
				<td>${result.question.id }</td>
				<td>${result.question.extraValue['orderId'].value }</td>
				<td>
					${result.question.description }
					</td>
					<td>
					${result.comment }
					</td>
				<td>
				<c-rt:if test="${result.priority==0}">
					函件
					</c-rt:if>
					<c-rt:if test="${result.priority==1}">
					一般件
					</c-rt:if>
					<c-rt:if test="${result.priority==2}">
					急件
					</c-rt:if>
					<c-rt:if test="${result.priority==3}">
					特急件
					</c-rt:if>
					</td>
					<td>${pu:menuOption('WorkOrder.status', pu:toString(result.status)).name }</td>
					<td>
					<c-rt:if test="${result.question.type.name=='CommonQuestion' }">
						<c-rt:if test="${result.question.extraValue['isProductQAA'].value=='true' }">
							商品问答
						</c-rt:if>
						<c-rt:if test="${result.question.extraValue['isProductQAA'].value!='true' }">
							客服问答
						</c-rt:if>
					</c-rt:if>
					<c-rt:if test="${result.question.type.name!='CommonQuestion' }">
					${result.question.type.description }
					</c-rt:if>
					
					</td>
					<td>
					
						
						${result.owner.username}
						
					
					</td>
					<td>
					<c-rt:if test="${!empty result.node.responseGroup}">
					${pu:get('com.yaodian100.core.admin.entity.Group', result.node.responseGroup).description }(${result.node.responseGroup })
					</c-rt:if>
					</td>
					<td>
					<c-rt:if test="${!empty result.node.approveGroup}">
					${pu:get('com.yaodian100.core.admin.entity.Group', result.node.approveGroup).description }(${result.node.approveGroup })
					</c-rt:if>
					</td>
					<td>
					<c-rt:if test="${result.approveStatus==0 }">
					待审核
					</c-rt:if>
					<c-rt:if test="${result.approveStatus==1 }">
					已核可
					</c-rt:if>
					<c-rt:if test="${result.approveStatus==2 }">
					<span style="color:red">已注销</span>
					</c-rt:if>
					</td>
					<td>
					<fmt-rt:formatDate value="${result.createDate }" pattern="yyyy/MM/dd HH:mm"/>
					</td>
					<td>
					${pu:reqSet('replyHql', 'from WorkOrder where parent.id=?') }
					${pu:reqSet('replyList', null) }
					${pu:listAdd('replyList', result.id) }
					${pu:reqSet('replyWorkOrder', pu:queryByHql(replyHql, pu:arrayGet('replyList'), null)) }
					
					<c-rt:if test="${!empty replyWorkOrder}">
					<c-rt:if test="${!empty replyWorkOrder[0].finishTime}">
					<fmt-rt:formatDate value="${replyWorkOrder[0].finishTime}" pattern="yyyy-MM-dd HH:mm"/>
					</c-rt:if>
					<c-rt:if test="${empty replyWorkOrder[0].finishTime}">
					<b>尚未回覆</b>
					</c-rt:if>
					</c-rt:if>
					<c-rt:if test="${empty replyWorkOrder}">
					未转单
					</c-rt:if>
					</td>
				</tr>
				<c-rt:if test="${empty result.parent}">
				<%
				WorkOrder wo=(WorkOrder)pageContext.getAttribute("result");
				StringBuffer sb=new StringBuffer();
				loopWoChild(sb, wo.getQuestion().getId(), 1);
				out.println(sb.toString());
				%>
				</c-rt:if>
				</c-rt:forEach>
				</tbody>
			</c-rt:forEach>
		
		
</table>
<c-rt:set var="url">
<%=application.getContextPath() %>/workOrder/page.do
</c-rt:set>
<pageable:Pageable url="${url}" escapeparams="iamlazy,AJAX,refreshZone,fromOrder" parameter="iamlazy=list&refreshZone=main&fromOrder=true" formname="woForm" key="tpp"></pageable:Pageable>
<table width="100%">
<tr>
<td align="right">
${pu:reqSet('currentPage', param.tpp_pageable_currentPage) }
<c-rt:if test="${empty param.tpp_pageable_currentPage}">
${pu:reqSet('currentPage', 1) }
</c-rt:if>
目前在第${currentPage }页, 资料共${tp.totalRecords }笔</td>
</tr>
</table>
</c-rt:if>
<script type="text/javascript" charset="UTF-8" src="/ecadmin/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/ecadmin/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/ecadmin/css/smoothness.datepick.css" />
<script>
$(document).ready(function(){
	
	$('#searchWorkOrder').click(function(){
		searchWorkOrderSubmit();
	});

	//每五分钟自动重整工单(setinterval單位：秒)
	setInterval(searchWorkOrderSubmit,300000);

	$('#startDate').datepick({dateFormat:'yy-mm-dd'});
	$('#endDate').datepick({dateFormat:'yy-mm-dd'});
	
});
function searchWorkOrderSubmit(){
	if(document.theForm.startDate.value!='' && !isValidDate(document.theForm.startDate.value)){
		alert('开始时间格式错误！');
		return;
	}else if(document.theForm.endDate.value!='' && !isValidDate(document.theForm.endDate.value)){
		alert('结束时间格式错误！');
		return;
	}
	$('iamlazy').attr('value', 'list');
	document.theForm.action='<%=application.getContextPath() %>/workOrder/page.do';
	document.theForm.submit();
}
function isValidDate(str){

	var expr = /^([1-2]{1,1}[0-9]{3,3})-([0-1]{1,1}[0-9]{1,1})-([0-3]{1,1}[0-9]{1,1})$/;
	if(!expr.test(str)){
	   return false;
	}
	var strs=str.split("-");
	if(strs.length!=3){
	   return false;
	}

	var date= new Date(parseFloat(strs[0]),parseFloat(strs[1])-1,parseFloat(strs[2]));
	if(date.getFullYear()==parseFloat(strs[0])&&(date.getMonth()+1==parseFloat(strs[1]))&&date.getDate()==parseFloat(strs[2])){
	   return date;
	}
	return false;
	}
</script>